<?php


namespace app\admin\model;


use think\Db;
use think\Model;

class YyDriverBase extends Model
{
    protected $table = 'yy_driver_base';

    public static function getDriverList($page, $limit, $data)
    {
        $where=[];
        if ($data['driver_phone']){
            $where['driver_phone']=$data['driver_phone'];
        }
        if ($data['province_id']){
            $where['province_id']=$data['province_id'];
        }
        if ($data['city_id']){
            $where['city_id']=$data['city_id'];
        }
        $start = ($page - 1) * $limit;
        $lists=Db::table('yy_driver_base')->where($where)->limit($start,$limit)->select();
        $count=Db::table('yy_driver_base')->where($where)->limit($start,$limit)->count();

        foreach ($lists as $k=>$v){
            $lists[$k]['province']=Db::table('xm_region')->where('region_id',$v['province_id'])->value('region_name');
            $lists[$k]['city']=Db::table('xm_region')->where('region_id',$v['city_id'])->value('region_name');
            switch ($v['commercial_type']){
                case 1:$lists[$k]['commercial_type']="网络预约出租车";break;
                case 2:$lists[$k]['commercial_type']="巡游出租车";break;
                case 3:$lists[$k]['commercial_type']="私人小客车合乘";break;
            }
        }
        return array(
            'code' => 0,
            'msg' => '',
            'count' => $count,
            'data' => $lists
        );
    }
    public static function getStatistical($page, $limit, $data)
    {
        $where=[];
        if ($data['driver_phone']){
            $where['a.driver_phone']=$data['driver_phone'];
        }
        if ($data['province_id']){
            $where['a.province_id']=$data['province_id'];
        }
        if ($data['city_id']){
            $where['a.city_id']=$data['city_id'];
        }
        $start = ($page - 1) * $limit;
        $lists=Db::table('yy_driver_base a')->join(['yy_driver_statistical_information'=>'b'],'a.driver_id=b.driver_id','right')->where($where)->limit($start,$limit)->select();
        $count=Db::table('yy_driver_base a')->join(['yy_driver_statistical_information'=>'b'],'a.driver_id=b.driver_id','right')->where($where)->limit($start,$limit)->count();
        return array(
            'code' => 0,
            'msg' => '',
            'count' => $count,
            'data' => $lists
        );
    }
}